<?php

session_start();
$hostname_con_gl = "localhost";
$database_con_gl = "db_research";
$username_con_gl = "root";
$password_con_gl = "";
$con_gl = mysql_pconnect($hostname_con_gl, $username_con_gl, $password_con_gl) or trigger_error(mysql_error(),E_USER_ERROR); 

function simple_encrypt($str){
	$rts = strrev($str);
	return base64_encode($rts);
}

function simple_decrypt($str){
	$rts = base64_decode($str);
	return strrev($rts);
}

//cekAkses($_SESSION[akses],"DD-2-4");
mysql_select_db($database_con_gl, $con_gl);
$query_klas = "SELECT kategori_id, kategori_nama FROM dcm_tm_kategori_dokumen ORDER BY kategori_nama ASC";
$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());
$row_klas = mysql_fetch_assoc($klas);
$totalRows_klas = mysql_num_rows($klas);


$query_status = "SELECT status_id, status_nama FROM dcm_ref_status_dokumen ORDER BY status_nama ASC";
$status = mysql_query($query_status, $con_gl) or die(mysql_error());
$row_status = mysql_fetch_assoc($status);
$totalRows_status = mysql_num_rows($status);

$query_action = "SELECT action_id, action_name FROM dcm_action ORDER BY action_name ASC";
$action = mysql_query($query_action, $con_gl) or die(mysql_error());
$row_action = mysql_fetch_assoc($action);
$totalRows_action = mysql_num_rows($action);


?>
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<link type="text/css" rel="stylesheet" href="../css/jquery.wysiwyg.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.wysiwyg.js"></script>
<script type="text/javascript">
$(function()
  {
	  $('#keterangan').wysiwyg();
  });

</script>
<body style="background:none;padding:8px;">
<?php if(isset($_POST['Save']))
 { ?>
<?php
// validasi data
$no_doc = $_POST['no_document'];
$nama_doc = $_POST['nama_document'];
$kat = $_POST['katagori'];
$status = 11; // untuk add pertama adalah request approval //$_POST['status'];
$action = 4; // in progress approval //$_POST['action'];
//$ars = $_POST['arsip'];
$fars= $_POST['filearsip'];
$ket = $_POST['keterangan'];
$f_tmp = $_FILES['filearsip']['tmp_name'];
$f_nam = str_replace(" ","",strtolower($_FILES['filearsip']['name']));
$f_tip = $_FILES['filearsip']['type'];
if($f_tip=='') {
	$error[] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Pilih file arsip yang ingin diupload !!!';
}
//echo $f_tip;
if (isset($error)) {
?>
<div id="loading" style="color:#FFF;border:solid 1px #F00;padding:5px;background:#F00;"><?php echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />".implode("<br />", $error); ?></div>
<?php }else{ ?>
<div id="loading" style="color:#1a4d80;border:solid 1px #215800;padding:5px;background:#F0FFED;">
<?php
	$query = "insert into dcm_tm_dokumen (kategori_id,tgl_upload,status_id,action_id,dokumen_no,dokumen_nama,tipe,keterangan) values ($kat,'2013-11-30','$status','$action','$no_doc','$f_nam','$f_tip','$ket')";
	$f_dest = "../data_arsip/".$f_nam;

	if(copy($f_tmp,$f_dest)) {
		mysql_select_db($database_con_gl, $con_gl);
		if(mysql_query($query, $con_gl)) {
			echo "<img src=\"../images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Tambah Arsip berhasil ...";
			echo "harusnya close ";
			echo "<script>top.opener.location.reload();self.close();</script>";
		}else{
			echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Tambah Arsip gagal, coba lagi !!!";	
		}
	}else{
		echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Tambah Arsip gagal, coba lagi !!!";	
}
?>
</div>
<?php } ?>
<?php } ?>
<h1>Tambah Data Document</h1>
<form action="" method="POST" enctype="multipart/form-data" name="add" id="add" >
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">No Document</td>
      <td bgcolor="#FFFFFF"><input name="no_document" type="text" id="no_document" size="37" maxlength="100" /></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Nama Document</td>
      <td bgcolor="#FFFFFF"><input name="nama_document" type="text" id="nama_document" size="37" maxlength="100" /></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Katagori Arsip : </td>
      <td bgcolor="#FFFFFF"><select name="katagori" id="katagori" style="width:200px;">
            <option value="">Pilih Katagori Document</option>
            <?php if($totalRows_klas > 0) { do { ?>
            <option value="<?php echo $row_klas['kategori_id'];?>"><?php echo $row_klas['kategori_nama'];?></option>
            <?php }while($row_klas = mysql_fetch_assoc($klas)); } ?>
          </select></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Status Document :</td>
      <td bgcolor="#FFFFFF"><strong>Request Approval</strong></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Action </td>
      <td bgcolor="#FFFFFF"><strong>In Progress Approval</strong></td>
    </tr>
    <tr valign="top">
      <td width="20%" align="right" bgcolor="#FFFFFF">Upload Document :</td>
      <td width="80%" bgcolor="#FFFFFF"><label>
        <input type="file" name="filearsip" id="filearsip" />
      </label></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Keterangan : </td>
      <td bgcolor="#FFFFFF"><label>
        <textarea name="keterangan" cols="85" rows="5" id="keterangan"></textarea>
        <input name="id" type="hidden" id="id" />
        <input name="kontak" type="hidden" id="kontak" value="<?php echo $_GET['id'];?>" />
      </label></td>
    </tr>
    <tr>
      <td align="left" bgcolor="#FFFFFF"><em>*Harus diisi
        <input name="open" type="hidden" id="open" value="<?php echo $_GET['open'];?>" />

      </em></td>
      <td bgcolor="#FFFFFF"><label>
        <input name="Save" type="submit" id="Save" value="Simpan" />
        </label>
        <label>
          <input type="button" name="Button" value="Batal" onClick="javascript:window.close(2000);" />
          <!--<input type="button" name="Button" value="Batal" onClick="javascript:window.close(2000);" />-->
        </label></td>
    </tr>
  </table>
</form>
</body>